package tds.study.payment.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

/**
 * 通用返回结果
 *
 * @author TongDaShuai
 * @since 2021/8/20
 */
@Data
@AllArgsConstructor
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 4994602318701974491L;

    /**
     * 返回码
     */
    private String code;

    /**
     * 返回信息
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;

    /**
     * 通用成功码
     */
    public static final String SUCCESS_CODE = "000000";

    /**
     * 通用成功信息
     */
    public static final String SUCCESS_MSG = "执行成功！";

    /**
     * 失通用败码
     */
    public static final String FAIL_CODE = "999999";

    /**
     * 通用失败信息
     */
    public static final String FAIL_MSG = "系统繁忙，请稍后重试！";

    public static <T> Result success(String msg, T data) {
        return new Result(SUCCESS_CODE, msg, data);
    }

    public static<T> Result success(T data) {
        return new Result(SUCCESS_CODE, "成功", data);
    }

    public static Result success() {
        return new Result(SUCCESS_CODE, "成功", null);
    }

    public static Result error(String msg) {
        return new Result(FAIL_CODE, msg, null);
    }

    public static Result error() {
        return new Result(FAIL_CODE, FAIL_MSG, null);
    }

}
